#pragma once

#include <QtWidgets/QMainWindow>
#include <QButtonGroup>
#include <QFile>
#include <QFileDialog>
#include <QCryptographicHash>
#include <QSqlDatabase>
#include <QSqlError>
#include <QSqlQuery>
#include <QDateTime>
#include "log.h"
#include "const.h"
#include <curl/curl.h>
#include "httpcommon.h"
#include "ui_download.h"
#include "downloaditem.h"
#include "globaldata.h"

class Download : public QWidget
{
    Q_OBJECT

public:
	Download(QWidget *parent = Q_NULLPTR);
	~Download();
	void downloadFile(QString id, QString name, bool showMsg);
	private Q_SLOTS:
	void transcodeDownloadSlot(QString id);
	void transcodeFailedDownloadSlot(QString id);
	void finishDownloadSlot(QString id, QString name);
	void pauseDownloadSlot(QString id);
	void resumeDownloadSlot(QString id);
	void deleteDownloadSlot(QString id);
	public Q_SLOTS:
	void on_pbStartAll_clicked();
	void on_pbPauseAll_clicked();
	void on_pbCancelAll_clicked();
Q_SIGNALS:
	void refreshFinishSignal();
	void showMessageSignal(QString, int);
private:
	void loadDownloadData();
	void addDownloadItem(QString itemID, QString recordID, QString name, QString status);
	QString getItemID();
private:
    Ui::Download ui;
	QString m_downloadUrl;
	QMap<QString, DownloadItem*> m_downloadMap;
	QString m_downloadTmpRootDir;
};
